/*
 * TODO[work-in-progress]: create a launcher (that works :p)
 */

package common;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 *
 */
public class Launcher {


    private static void printLines(String name, InputStream ins) throws Exception
    {
        String line = null;
        BufferedReader in = new BufferedReader(
                new InputStreamReader(ins));
        while ((line = in.readLine()) != null)
        {
            System.out.println(name + " " + line);
        }
    }

    private static Process runProcess(String command) throws Exception
    {
        Process pro = Runtime.getRuntime().exec(command);
        printLines(command + " stdout:", pro.getInputStream());
        printLines(command + " stderr:", pro.getErrorStream());
        pro.waitFor();
        System.out.println(command + " exitValue() " + pro.exitValue());

        return pro;
    }

    public static void main(String args[])
    {
        Process pro = null;
        // theProcess = Runtime.getRuntime().exec("java com.ibm.as400.system.Hello");
        try
        {
            // runProcess("javac src/serveursvg/Main.java");
            // runProcess("java -cp build/classes/serveursvg.Main");
            pro = runProcess(
                    "java -cp build/classes/ serveursvg.RmiServerSVGWriterRunner");
        } catch (Exception e)
        {
            System.out.println("TODO: log this up");
        }
        System.out.println("Process:" + pro);
    }
}
